<template>
  <div class="count_box">
    <button class="del" @click="del">-</button>
    <input type="text" class="inp" :value="value" @change="hadelChange">
    <button class="add" @click="add">+</button>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default: 1
    }
  },
  methods: {
    add () {
      this.$emit('input', this.value + 1)
      console.log(1)
    },
    del () {
      if (this.value <= 1) {
        return
      }
      this.$emit('input', this.value - 1)
    },
    hadelChange (e) {
      const num = +e.target.value
      if (isNaN(num) || num < 1) {
        e.target.value = this.value
        return
      }
      this.$emit('input', num)
    }
  }
}
</script>

<style lang="less" scoped>
.count_box{
    width: 110px;
    display: flex;
}
.add,.del {
    width: 30px;
    height: 30px;
    outline: none;
    border: none;
    background-color: #efefef;
}
.inp {
    width: 40px;
    height: 30px;
    outline: none;
    border: none;
    background-color: #efefef;
    margin: 0 5px;
    text-align: center;
}
</style>
